<template>
  <div class="menus-page">
    <div class="page-header">
      <h1>菜单管理</h1>
      <el-button type="primary" @click="handleCreate" v-if="$authStore.hasPermission('menu:create')">
        <el-icon><Plus /></el-icon>
        新增菜单
      </el-button>
    </div>

    <div class="menus-content">
      <el-table :data="menuList" stripe row-key="id" tree-props="{ children: 'children' }">
        <el-table-column prop="menuName" label="菜单名称" />
        <el-table-column prop="menuCode" label="菜单编码" />
        <el-table-column prop="menuUrl" label="菜单路径" />
        <el-table-column prop="menuIcon" label="图标" width="100" />
        <el-table-column prop="sort" label="排序" width="80" />
        <el-table-column label="状态" width="100">
          <template #default="{ row }">
            <el-tag :type="row.status ? 'success' : 'danger'">
              {{ row.status ? '启用' : '禁用' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template #default="{ row }">
            <el-button 
              size="small" 
              type="primary" 
              @click="handleEdit(row)"
              v-if="$authStore.hasPermission('menu:update')"
            >
              编辑
            </el-button>
            <el-button 
              size="small" 
              type="danger" 
              @click="handleDelete(row)"
              v-if="$authStore.hasPermission('menu:delete')"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'
import { useAuthStore } from '@/stores/auth'

const authStore = useAuthStore()

const menuList = ref([
  {
    id: '1',
    menuName: '系统管理',
    menuCode: 'system',
    menuUrl: '/system',
    menuIcon: 'Setting',
    sort: 1,
    status: 1,
    children: [
      {
        id: '2',
        menuName: '用户管理',
        menuCode: 'user',
        menuUrl: '/system/users',
        menuIcon: 'User',
        sort: 1,
        status: 1
      },
      {
        id: '3',
        menuName: '角色管理',
        menuCode: 'role',
        menuUrl: '/system/roles',
        menuIcon: 'UserFilled',
        sort: 2,
        status: 1
      }
    ]
  },
  {
    id: '4',
    menuName: '内容管理',
    menuCode: 'content',
    menuUrl: '/content',
    menuIcon: 'Document',
    sort: 2,
    status: 1,
    children: [
      {
        id: '5',
        menuName: '文章管理',
        menuCode: 'article',
        menuUrl: '/archives',
        menuIcon: 'Edit',
        sort: 1,
        status: 1
      }
    ]
  }
])

const handleCreate = () => {
  ElMessage.info('新增菜单功能开发中')
}

const handleEdit = (row) => {
  ElMessage.info(`编辑菜单: ${row.menuName}`)
}

const handleDelete = (row) => {
  ElMessage.info(`删除菜单: ${row.menuName}`)
}
</script>

<style scoped>
.menus-page {
  background: white;
  border-radius: 8px;
  padding: 20px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
</style>